/**
  ******************************************************************************
  * @file    at24c02.c
  * @brief   This file provides code for the configuration
  *          of the AT24C02 instances.
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2023 STMicroelectronics.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file
  * in the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  *
  ******************************************************************************
  */
/* Includes ------------------------------------------------------------------*/
#include "at24c02.h"

/* Defines -------------------------------------------------------------------*/

/* Variables -----------------------------------------------------------------*/

/* Prototypes ----------------------------------------------------------------*/
Uint16 AT24C02_Read1Byte(Uint16 reg)
{
	Uint16 temp;
	I2CSendNoStop(0x50,reg);
	while((I2caRegs.I2CSTR.all & I2C_ARDY_BIT) == 0)
	{
		temp++;
		if(temp > 100*1000)
			return 0;
	}
	I2caRegs.I2CSTR.all |= I2C_ARDY_BIT;
	I2CARecvSTOP(0x50,1);
	while((I2caRegs.I2CSTR.all & I2C_SCD_BIT)==0)
	{
		temp++;
		if(temp > 100*1000)
			return 0;
	}
	I2caRegs.I2CSTR.all |= I2C_SCD_BIT;
	while(I2caRegs.I2CFFRX.bit.RXFFST)
	{
		temp = I2caRegs.I2CDRR;
	}
	return temp;
}

Uint16 AT24C02_Write1Byte(Uint16 reg,Uint16 data)
{
	Uint16 temp = 0;
	I2CSendStop(0x50,reg,data);
	while((I2caRegs.I2CSTR.all & I2C_SCD_BIT)==0)
	{
		temp++;
		if(temp > 100*1000)
			return 0;
	}
	I2caRegs.I2CSTR.all |= I2C_SCD_BIT;
	return 1;
}
